package com.yanqu.road.server.cmd.activity.stronghold.cross;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.activity.stronghold.eStrongholdEventType;
import com.yanqu.road.pb.activity.StrongholdWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.strongholdwar.StrongholdModule;
import com.yanqu.road.server.manger.activity.strongholdwar.StrongholdActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_CROSS_STRONGHOLD_SINGLE_WILD, desc = "")
public class CrossSingleWildCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo openActivityInfo = StrongholdActivityMgr.getOpenActivityInfo();
        if (openActivityInfo != null) {
            player.getModule(StrongholdModule.class).setEventConsume(openActivityInfo.getActivityId(), null);
            StrongholdWarProto.StrongholdDataResp msg = StrongholdWarProto.StrongholdDataResp.parseFrom(packet.getBytes());
            if (msg.hasEvent()) {
                StrongholdWarProto.StrongholdEventTempMsg event = msg.getEvent();
                int type = event.getType();
                if (type == eStrongholdEventType.NPC.getValue()) {
                    //只记录NPC事件
                    String consume = event.getNpcEvent().getConsume();
                    player.getModule(StrongholdModule.class).setEventConsume(openActivityInfo.getActivityId(), consume);
                }
            }
            player.sendPacket(ClientProtocol.U_STRONGHOLD_WAR_WILD_DATA, msg.toBuilder());
        }
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
